using System.Activities.Statements;
using System.Activities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Headsight.BPMN2WF.Testing
{
    [TestClass]
    public class Flowchart4TestHelperTest
    {
        private Flowchart4TestHelper _sut;
 
        [TestInitialize]
        public void SetUp()
        {
            _sut = new Flowchart4TestHelper();
        }

        [TestMethod]
        public void Root()
        {
            var result = _sut.Root;

            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(ActivityBuilder), result.ItemType);
        }
        
        [TestMethod]
        public void Implementation()
        {
            var result = _sut.Implementation;

            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(Flowchart), result.ItemType);
        }

        [TestMethod]
        public void CreateStartNode()
        {
            var startNode = _sut.CreateStartNode();

            Assert.IsNotNull(startNode);

            var propStartNode = _sut.Implementation.Properties["StartNode"];
            Assert.IsNotNull(propStartNode);
            Assert.AreSame(startNode, propStartNode.Value);
        }

        [TestMethod]
        public void CreateStartNode_CreateNextNode()
        {
            var startNode = _sut.CreateStartNode();
            var nextNode  = _sut.CreateNextNode();

            Assert.IsNotNull(nextNode);
            Assert.AreSame(nextNode, startNode.Properties["Next"].Value);
        }

        [TestMethod]
        public void CreateStartNode_CreateNextNode_CreateNextNode()
        {
            _sut.CreateStartNode();
            var nextNode1 = _sut.CreateNextNode();
            var nextNode2 = _sut.CreateNextNode();

            Assert.IsNotNull(nextNode2);
            Assert.AreSame(nextNode2, nextNode1.Properties["Next"].Value);
        }

        [TestMethod]
        public void CreateStartNode_CreateTrueAndFalse()
        {
            var startNode = _sut.CreateStartNode();
            var trueAndFalse = _sut.CreateTrueAndFalse();

            Assert.IsNotNull(trueAndFalse);
            Assert.AreEqual(3, trueAndFalse.Length);
            Assert.AreSame(trueAndFalse[0], startNode.Properties["Next"].Value);

            Assert.AreSame(trueAndFalse[1], trueAndFalse[0].Properties["True"].Value);
            Assert.AreSame(trueAndFalse[2], trueAndFalse[0].Properties["False"].Value);
        }
    }
}